#include "pro.h"
#include <unistd.h>
#include <time.h>
#include <stdlib.h>
//下载的总量
double total = 1024.0;
//网速
double speed[] = {1.2,5.6,0.5,0.2,0.09,0.07};
//函数指针
typedef void (*call_t)(double,double);

void down(int total , call_t cb)
{
    //随机数种子
    srand(time(NULL));
    //下载量
    double curr = 0.0;
    while(curr <= total)
    {
        //更新进度
        cb(total,curr);
        // 如果已下载量达到或超过总量，跳出循环
        if(curr>=total)
        {
            break;
        }
        // 生成一个0到5之间的随机整数，用于从网速数组中选取网速
        int random  = rand() % 6; 
        //下载代码
        usleep(5000);
        //根据网速动态下载
        curr += speed[random];
        // 如果已下载量超过了总量，将其设置为总量
        if(curr >= total)
        {
            curr = total;
        }
    }
}


int main()
{
   down(1024,FflushPro);
    return 0;
}
